package xiangmu.schoolpaper.service.impl.system;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xiangmu.schoolpaper.pojo.DTO.MajorAndIdDTO;
import xiangmu.schoolpaper.pojo.DTO.MajorDTO;
import xiangmu.schoolpaper.pojo.VO.MajorAndIdVO;
import xiangmu.schoolpaper.pojo.VO.TemplateTypeVO;
import xiangmu.schoolpaper.service.system.TemplateTypeService;
import xiangmu.schoolpaper.mapper.system.TemplateTypeMapper;

import java.time.LocalDateTime;


@Service
public class TemplateTypeServiceImpl implements TemplateTypeService {
    @Autowired
    public TemplateTypeMapper templateTypeMapper;
    @Override
    public void updateTemplateType(TemplateTypeVO templateType) {
        templateType.setUpdatedTime(LocalDateTime.now());
        templateTypeMapper.updateTemplateType(templateType);
    }

    @Override
    public void disableTemplateType(TemplateTypeVO integer) {
        templateTypeMapper.disableTemplateType(integer);
    }

    @Override
    public MajorAndIdVO getMajor(Integer id) {
        return templateTypeMapper.getMajor(id);
    }

    @Override

    public Integer addMajor(MajorAndIdVO majorAndIdVO) {
//        String major=majorAndIdVO.getMajorName();
        MajorDTO major =new MajorDTO();
        major.setMajorName(majorAndIdVO.getMajorName());
        major.setCreatedTime(LocalDateTime.now());
        major.setUpdatedTime(LocalDateTime.now());
        major.setDelFlag(1);
        templateTypeMapper.addMajor(major);
        Integer pos= templateTypeMapper.selectMajorId(major.getMajorName());
        if(pos==null){
            return -1;
        }else {
            return pos;
        }
    }

    @Override
    public void deleteMajor(Integer id) {
        templateTypeMapper.deleteMajor(id);
    }

    @Override
    public void updateMajor(MajorAndIdDTO majorAndIdDTO) {
        MajorDTO major =new MajorDTO();
        BeanUtils.copyProperties(majorAndIdDTO,major);
        major.setUpdatedTime(LocalDateTime.now());
        templateTypeMapper.updateMarjor(major);
    }

}
